package com.odobenus.client.tools;
import java.io.IOException;
import java.util.Properties;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import com.odobenus.client.properties.OdobenusProperties;


public class PropertiesUtil {
    private static final String path = "/application.properties";
    public static final Resource resource = new ClassPathResource(path);
    public  static Properties props=null;
    static {
        try {
            props = PropertiesLoaderUtils.loadProperties(resource);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取指定key的value
     * @param key
     * @return
     */
    private static String getProperty(String key)  {
        return props.getProperty(key);
    }
    public static OdobenusProperties loadContext() {
    	OdobenusProperties odobenusProperties = new OdobenusProperties();
		odobenusProperties.setApp(PropertiesUtil.getProperty("odobenus.app"));
		odobenusProperties.setEnableRemote(Boolean.valueOf(PropertiesUtil.getProperty("odobenus.enableRemote")));
		odobenusProperties.setServerHost(PropertiesUtil.getProperty("odobenus.serverHost"));
		odobenusProperties.setEnv(PropertiesUtil.getProperty("odobenus.env"));
		odobenusProperties.setVersion(PropertiesUtil.getProperty("odobenus.version"));
		odobenusProperties.setMode(PropertiesUtil.getProperty("odobenus.mode"));
		odobenusProperties.setLocalDownDir(PropertiesUtil.getProperty("odobenus.localDownDir"));
		return odobenusProperties;
    }
}